function AppAssistant() {
	this.remote = true;
	// stages with default scenes
	this.stages = {
		register: { name: 'cardStage', scene: 'register', type: 'card' },
		dashboard: { name: 'dashboardStage', scene: 'dash', type: 'dashboard' },
		status: { name: 'statusStage', scene: 'status', type: 'card' }
	};
}

AppAssistant.prototype.launchStage = function(stage) {
	var c = this.controller;
	var proxy = c.getStageProxy(stage.name);
	var controller = c.getStageController(stage.name);
	var stageArgs = { name: stage.name, lightweight: true };
	var pushSceneFn = function(sc) { sc.pushScene(stage.scene); };
	if (proxy && controller) {
		say('launchStage: activating ' + stage.name);
		controller.activate();
	} else {
		say('launchStage: creating ' + stage.name + ' as ' + stage.type);
		c.createStageWithCallback(stageArgs, pushSceneFn, stage.type );
	}
};

AppAssistant.prototype.connect = function() {
	var jid = utils.get().user + "@" + utils.get().domain;
	var pw = utils.get().user;
	var host = 'http://' + utils.get().host + '/xmpp-httpbind';
	xmpp.connect(host,jid,pw);
};
AppAssistant.prototype.handleLaunch = function(params) {
	var c = this.controller;
	var source = params && params.source;
	var stage = this.stages.register;

	say('');
	say('');
	say('');
	say('handleLaunch', source);

	if (utils.get().user) {
		stage = this.stages.status;

//		if (source == 'status-close') {
//			stage = this.stages.dashboard;
//		}
//		if (xmpp.isDisconnected()){
//			this.connect();
//			this.launchStage(this.stages.dashboard);
//		}
	}
	this.launchStage(stage);
};
AppAssistant.prototype.handleCommand = function(ev) {
	var c = this.controller.getStageController('configStage');
	if (ev.type === Mojo.Event.command) {
		switch(ev.command) {
			case 'config':
				c.swapScene('config');
				break;
			case 'status':
				c.swapScene('status');
				break;
			case 'history':
				c.swapScene('history');
				break;
			default:
				console.log('unknown command: ' + ev.command);
				break;
		}
	}
};

AppAssistant.cmdMenuModel = {
	visible: true,
	items: [
		{ 
			items: [
				{ label: 'Config', command: 'config'},
				{ label: 'Status', command: 'status'},
				{ label: 'History', command: 'history' }
			]
		}
	]
};
